package com.itheima.aop;

import lombok.extern.log4j.Log4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Log4j
public class RunTimeAspect {
    @Around("execution(* com.itheima..service..*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        //开始时间
        long start = System.currentTimeMillis();
        //调用目标方法
        Object result = pjp.proceed(pjp.getArgs());
        //结束时间
        long end = System.currentTimeMillis();
        //获取目标类的名字和目标方法的名字
        String typeName = pjp.getSignature().getDeclaringTypeName();
        String name = pjp.getSignature().getName();
        log.info(typeName + "中的" + name + "方法，执行花费了" + (end - start) + "毫秒");
        return result;
    }
}
